Page({
  onLoad() {
    console.log('🏠 主页加载');
  },

  chooseOrderUser() {
    const app = getApp();
    app.setUserRole('order_user');
    wx.showToast({ title: '已切换到下单者身份' });
    setTimeout(() => {
      wx.reLaunch({ url: '/pages/login/login' });
    }, 500);
  },

  chooseCourier() {
    const app = getApp();
    app.setUserRole('courier');
    wx.showToast({ title: '已切换到代拿员身份' });
    setTimeout(() => {
      wx.reLaunch({ url: '/pages/login/login' });
    }, 500);
  },

  onShow() {
    // 检查是否已选择身份，如果已选择则直接跳转
    const userRole = getApp().globalData.userRole;
    if (userRole === 'order_user') {
      wx.reLaunch({ url: '/pages/orderUser/orderUser' });
    } else if (userRole === 'courier') {
      wx.reLaunch({ url: '/pages/courier/courier' });
    }
  }
});